<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib tagdir="/WEB-INF/tags/busterminal/" prefix="bt"%>
<%@taglib uri="/WEB-INF/tags/tlds/Functions.tld" prefix="f"%>

<c:set var="user" scope="session" value="${user}" />
<c:if test="${f:isActionAllowed('scheduled.item.find.by.time', user.getRole())}">
    <a class="btn btn-mini" href="MainServlet?action=scheduled.item.find.by.time" id="show-results-list" data-toggle="tab"><i class="icon-time icon-white"></i>&nbsp;Nearest items</a>
</c:if>
<table class="table table-striped table-bordered table-condensed">
    <caption>Scheduled item list</caption>
    <thead>
        <tr>
            <th>Route</th>
            <th>Departure time</th>
            <th>Arrival time</th>
            <th>Travel time</th>
            <th>Departure time from end point</th>
            <th>Arrival time to bus terminal</th>
            <th>Routing days</th>
            <th>Platform number</th>
            <c:if test="${f:isActionAllowed('scheduled.item.edit', user.getRole())}">
                <th>&nbsp;</th>
            </c:if>
            <c:if test="${f:isActionAllowed('scheduled.item.delete', user.getRole())}">
                <th>&nbsp;</th>
            </c:if>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="scheduledItem" items="${scheduledItemList}">
            <tr>
                <c:choose>
                    <c:when test="${f:isActionAllowed('route.one.list', user.getRole())}">
                        <c:url var="routeURL" value="MainServlet">
                            <c:param name="action" value="route.one.list" />
                            <c:param name="id" value="${scheduledItem.getRoute().getId()}" />
                        </c:url>
                        <td><a href="${routeURL}"><c:out value="${scheduledItem.getRoute().getRouteName()}" /></a></td>
                    </c:when>
                    <c:when test="${not f:isActionAllowed('route.one.list', user.getRole())}">
                        <td><c:out value="${scheduledItem.getRoute().getRouteName()}" /></td>
                    </c:when>
                </c:choose>
                <td><c:out value="${scheduledItem.getDepartureTime().toString()}" /></td>
                <td><c:out value="${scheduledItem.getArrivalTime().toString()}" /></td>
                <td><c:out value="${scheduledItem.getTravelTime().toString()}" /></td>
                <td><c:out value="${scheduledItem.getDepartureTimeFromEndPoint().toString()}" /></td>
                <td><c:out value="${scheduledItem.getArrivalTimeToBusTerminal().toString()}" /></td>
                <td><c:out value="${scheduledItem.getRoutingDaysString()}" /></td>
                <td><c:out value="${scheduledItem.getPlatformNumber()}" /></td>
                <c:if test="${f:isActionAllowed('scheduled.item.edit', user.getRole())}">
                    <c:url var="editURL" value="MainServlet">
                        <c:param name="action" value="scheduled.item.edit" />
                        <c:param name="id" value="${scheduledItem.getId()}" />
                    </c:url>
                    <td nowrap width="48"><a class="btn btn-mini" href="${editURL}" id="show-edit-form" data-toggle="tab"><i class="icon-pencil icon-white"></i>&nbsp;Edit</a></td>
                </c:if>
                <c:if test="${f:isActionAllowed('scheduled.item.delete', user.getRole())}">
                    <c:url var="deleteURL" value="MainServlet">
                        <c:param name="action" value="scheduled.item.delete" />
                        <c:param name="id" value="${scheduledItem.getId()}" />
                    </c:url>
                    <td nowrap width="62"><a class="btn btn-mini" id="show-delete-dialog" data-target="#delete-modal-window" data-toggle="modal" data-link="${deleteURL}" data-name="${scheduledItem.getRoute().getRouteName()}; ${scheduledItem.getDepartureTime().toString()}-${scheduledItem.getArrivalTime().toString()}; ${scheduledItem.getRoutingDaysString()}"><i class="icon-trash icon-white"></i>&nbsp;Delete</a></td>
                </c:if>
            </tr>
        </c:forEach>
        <c:if test="${f:isActionAllowed('scheduled.item.create', user.getRole())}">
            <tr>
                <td colspan="10">
                    <a class="btn btn-mini" href="MainServlet?action=scheduled.item.create" id="show-create-form" data-toggle="tab"><i class="icon-plus icon-white"></i>&nbsp;New scheduled item</a>
                </td>
            </tr>
        </c:if>
    </tbody>
</table>
<bt:DeleteDialog entity="scheduled item" />